package cn.disicn.controller;

import org.apache.commons.lang3.StringUtils;

import com.jfinal.core.Controller;

import cn.disicn.common.Const;
import cn.disicn.common.ServerResponse;
import cn.disicn.model.SecPublishRefundInfo;

/**
 * 退款相关
 * 
 * @author luyao
 */
public class RefundController extends Controller {

	private static final SecPublishRefundInfo refundInfo = new SecPublishRefundInfo();

	/**
	 * 获取退款记录
	 */
	public void index() {
		Integer pageNum = getParaToInt("pageNum");
		Integer pageSize = getParaToInt("pageSize");
		// 获取退款状态
		String status = getPara("status");
		// 获取搜索的手机号
		String phone = getPara("phone");
		if (pageNum != null && pageSize != null && pageNum > 0 && pageSize > 0) {
			renderJson(refundInfo.getRefundApplication(pageNum, pageSize, status, phone));
		} else {
			renderJson(ServerResponse.createByErrorMsg(Const.ErrorResult.PARAMETER_ERROR));
		}
	}

	/**
	 * 执行退款
	 */
	public void toRefund() {
		String jobId = getPara("jobId");
		if (!StringUtils.isBlank(jobId) && jobId.length() == 32) {
			renderJson(refundInfo.toRefund(jobId, getRequest()));
		} else {
			renderJson(ServerResponse.createByErrorMsg(Const.ErrorResult.PARAMETER_ERROR));
		}
	}

	/**
	 * 获取所有退款人的手机号
	 */
	public void getAllPhone() {
		renderJson(refundInfo.getAllPhone());
	}

}
